function generate(numRows: number): number[][] {
  let arr: Array<number>[] = [];
  if (numRows === 1) {
    return [[1]];
  } else if (numRows === 2) {
    return [[1], [1, 1]];
  } else {
    arr.push([1]);
    arr.push([1, 1]);
    for (let i = 2; i < numRows; i++) {
      arr.push([]);
      for (let j = 0; j <= i; j++) {
        if (j === 0 || j === i) {
          arr[i][j] = 1;
        } else {
          arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
        }
      }
    }
  }
  return arr;
}
console.log(generate(5));
